這一次的主題一樣是輕量資料庫SQLite的語法,這是我寫資料庫的第四篇了,想不到資料庫這麼有趣,雖然每天只學會一點點,但是也讓我每天都會資料庫加深印象,這次會教大家幾個常用的語句。
SELECT [指定欄位(多) or *] FROM 表格名稱 [WHERE condition] ORDER BY [指定欄位1,欄位2..] ASC;
ex: SELECT * FROM STUDENT ORDER BY AGE ASC;
SELECT [指定欄位(多) or *] FROM 表格名稱 [WHERE condition] ORDER BY [指定欄位1,欄位2..] DESC;
ex: SELECT * FROM STUDENT ORDER BY AGE DESC;
SELECT [欄位1(具有相同欄位值)],SUM/MAX/MIN[欄位二] FROM [表格名稱] WHERE [特定欄位] GROUP BY [欄位1]
ORDER BY [欄位1]
SELECT 部門,SUM(年齡) FROM DATA GROUP BY 部門;
SELECT 部門,MAX(年齡) FROM DATA GROUP BY 部門;
SELECT 部門,MIN(年齡) FROM DATA GROUP BY 部門;
SELECT [欄位1],[欄位2] FROM table1, table2 WHERE [特定欄位] GROUP BY [欄位1] HAVING [過濾條件式] ORDER BY [欄位1]
目前的表格內容
顯示年齡大於20的所有資料